<?php
namespace app\index\controller;

use Single;

class Index
{
    public function index2()
    {
        /**单例模式测试代码 */
        print_r(\Single::getInstance()->abc());
        print_r(\Single::getInstance()->abc());
        print_r(\Single::getInstance()->abc());
        print_r(\Single::getInstance()->abc());
        print_r(\Single::getInstance()->abc());
        print_r(\Single::getInstance()->abc());
    }

    public function index(){
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改（2006-2018） - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
    }

    public function yaconf(){
        $title = yaconf('title');
        print($title);

    }

    public function register(){
        $a=new \A();
        // \SingwaRegister::set('singwa',$a); //添加到注册树中

        // $abc=\SingwaRegister::get('singwa'); //获取到当前模型
        
        $abc=\SingwaRegister::get('A'); //获取到当前模型

        dump($abc->abc());

    }

    public function personbuy(){ //测试依赖注入

        // $bmw=new \di\Car();
        // $person=new \di\Person($bmw);
        // var_dump($person->buy());

        \di\Container::getInstance()->set('person','\di\Person');
        \di\Container::getInstance()->set('car','\di\Car');

        $obj=\di\Container::getInstance()->get('person');

        var_dump($obj->buy());
    }

    public function rel(){ //反射
        $obj=new \A();
        // var_dump($obj); // 打印 A类 object(A)#34 (2) { ["a"]=> int(1) ["abc":"A":private]=> int(2) }

        $obj2=new \ReflectionClass($obj);
        // var_dump($obj2); // 打印 反射类  object(ReflectionClass)#35 (1) { ["name"]=> string(1) "A" }

        $instance=$obj2->newInstance(); //相当于实例化A类
        // var_dump($instance);  // object(A)#36 (2) { ["a"]=> int(1) ["abc":"A":private]=> int(2) } 

        $methods=$obj2->getMethods(); //获取类中的方法
        // var_dump($methods);die();  // array(3) { [0]=> object(ReflectionMethod)#37 (2) { ["name"]=> string(3) "abc" ["class"]=> string(1) "A" } [1]=> object(ReflectionMethod)#38 (2) { ["name"]=> string(2) "mf" ["class"]=> string(1) "A" } [2]=> object(ReflectionMethod)#39 (2) { ["name"]=> string(3) "ddd" ["class"]=> string(1) "A" } }

        // foreach ($methods as $key => $m) {
        //     var_dump($m->getDocComment()); //获取注释内容
        // }

        $properties=$obj2->getProperties(); //获取类的属性
        var_dump($properties);die(); //  array(2) { [0]=> object(ReflectionProperty)#40 (2) { ["name"]=> string(1) "a" ["class"]=> string(1) "A" } [1]=> object(ReflectionProperty)#41 (2) { ["name"]=> string(3) "abc" ["class"]=> string(1) "A" } }

        //调用方法 方式一
        echo $instance->abc(1,2);
        //调用方法 方式二
        $method=$obj2->getMethod("abc");
        echo $method->invokeArgs($instance,['mmmm','555444a']);
        //调用方法 方式三
        $method=$obj2->getMethod("ddd");
        echo $method->invoke($instance);

        /**判断某个方式是否是公用的 */
        $method=new \ReflectionMethod($obj,"ddd");
        if($method->isPublic()){
            echo '是公用方法';
        }

        $method2=new \ReflectionMethod($obj,"abc");
        dump($method2->getParameters()); //获取参数
        dump($method2->getNumberOfParameters()); //获取参数个数
    }

    public function count(){
        $obj=new \SingwaCount();
        // echo $obj->count(); // 返回 234
        echo count($obj); // 返回 234
    }

    public function container(){
        $config = new \Config(); //第一种方式
        dump($config::get('app.')); //获取配置

        $config=Container()::get('config')->get('app.'); //容器类获取
        dump($config);
        
        $config=app('config'); // 第三种方式
        dump($config->get('app.'));
    }

    public function test(){
        $t=new \Test();
        $t->def();
    }

    public function facade(){
        // dump(\Config::get('app.')); //获取方式
        // dump(\think\facade\Config::get('app.')); //最终获取方式

        // $singwa = new \app\common\Singwa(); //第一种类的调用方式
        // $singwa->abc();

        // \app\facade\Singwa::abc(); // 通过门面方式调用类

        \think\Facade::bind('app\facade\Xiaoliu','app\common\Xiaoliu');
        \app\facade\Xiaoliu::abc();
    }


}
